import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
// 初始化样式
import 'normalize.css';
// 引入elementui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

// 配置路由守卫
router.beforeEach((to, from, next) => {
	//判断是否为登录页
	if (to.path == '/') {
		next(); //去往登录页直接放行
	} else {
		// 去往其他页面检查是否获得Token
		if (sessionStorage.getItem('token')) {
			next();
		} else {
			// 没有获取Token返回登录页
			next({ path: '/', replace: true });
		}
	}
});

import http  from "@/utils/request";
Vue.prototype.$http = http

import axios from 'axios';
// 配置全局axios的请求根路径
axios.defaults.baseURL = '/api';
// 将axios挂载到this上
Vue.prototype.$axios = axios;

Vue.config.productionTip = false;

new Vue({
	router,
	store,
	render: (h) => h(App),
}).$mount('#app');
